***                    REPLICATION AND COMMAND FILES FOR "Lasse Laustsen & Michael Bang Petersen:                        ***
* When the Party Decides: The Effects of Facial Competence and Dominance on Internal Nominations of Political Candidates *



// Includes only candidates from mainstream Danish parties (i.e. excludes local party lists)
 *Creates dummy for candidates from main parties versus local party lists
generate local =.
replace local = 1 if Parti ==1
replace local = 1 if Parti ==2
replace local = 1 if Parti ==3
replace local = 1 if Parti ==4
replace local = 1 if Parti ==5
replace local = 1 if Parti ==6
replace local = 1 if Parti ==7
replace local = 1 if Parti ==8

replace local = 0 if Parti ==9
replace local = 0 if Parti ==10
replace local = 0 if Parti ==11
replace local = 0 if Parti ==12



// Creates variable for candiadte party by separating candidates belonging to the "liberal" or the "conservative" party family/block
gen liberal = (Parti==1 | Parti==2 | Parti==4 | Parti==8)

gen conservative = (Parti==3 | Parti==5 | Parti==6 | Parti==7)


//Labeling of control and moderator variables
* Candidate sex
label define KønLB 0 "male" 1 "female"
label values Kon KønLB 

* Party block
label define liberalLB 0 "Liberal" 1 "Conservative"
label values liberal liberalLB 

* Perceived age
label define alder_nyLB 1 "younger than 30" 2 "between 30 and 60" 3 "over 60"
label values alder_ny alder_nyLB 

* Incumbency
label define Valgt_forLB 0 "non incumbent" 1 "incumbent"
label values Valgt_for Valgt_forLB

* Local municipality
label define KommuneLB 1 "Brønderslev" 2 "Frederikshavn" 3 "Mariager Fjord"
label values Kommune KommuneLB 


*** Descriptive statistics for control variables

* Categorical variable for candidate sex
tab Kon

* Categorical variable for party block
tab liberal 

* Categorical variable for perceived age of the candidates in three categories (1: below 30 years; 2: between 30 and 60 years; 3: over 60 years)
tab alder_ny

* Categorical variable for incumbency
tab Valgt_for

* Categorical variable measuring which of the three different municipalities a candidate is nominated in
tab Kommune



*------------------------------- Generates Dependent Variables: Ballot list position ---------------------------------------------*

*** "Raw" position on the ballot list
summ Listeplacering

*** Creates different variables for nomination success that takes a list's number of candidates into account

** Relative measure: Positioon divided by number of candidates nominated for the party
generate RelList = Listeplacering/Liste_kandidater
* Change the direction of the relative measure such that high number equals better position
generate RelativListe = ((RelList*-1)+1)

** Creates a series of different dichotomous measures:
* Top 20 percent
recode RelList (0/0.20 = 1) (0.21/1 = 0), generate(top20pct)

* Top 25 percent
recode RelList (0/0.24 = 1) (0.25/1 = 0), generate(top25pct)

* Top 30 percent
recode RelList (0/0.30 = 1) (0.30000001/1 = 0), generate(top30pct)

* Top 40 percent
recode RelList (0/0.40 = 1) (0.40000001/1 = 0), generate(top40pct)

* Top 50 percent
recode RelList (0/0.50 = 1) (0.51/1 = 0), generate(top50pct)



*------------------------ Creates Main Independent Variables: Facial Competence and Facial Dominance ---------------------------------*
** Principal Component Analysis of the seven face-based trait perceptions
factor Ansvarsfuld Intelligent Kompetent Attraktivitet Venlig Fysisk_styrke Dominerende, pcf factors(2)

* Extracts competence and non-dominance components/variables
predict Comp NonDom

** Recodes Competence variable to scale from 0 to 1 reflecting min. and max. observed facial competence
summ Comp
generate Competence = (Comp-r(min))/(r(max)-r(min))

** Recodes Dominance variable to scale from 0 to 1 reflecting min. and max. observed facial dominance
summ NonDom
generate NonDominance = (NonDom-r(min))/(r(max)-r(min))

* Changes direction of variable from non-dominance to dominance
generate Dominance = ((NonDominance*-1)+1)



*-------------------------------------------MAIN ANALYSES AND FIGURES------------------------------------------------------------------*

******Prediction of ballot position in top 20 percent from facial competence and facial dominance X ideology (Table 1: Model 1)
logit top20pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon Competence i.conservative##c.Dominance if local==1, cluster(Parti)


******Prediction of ballot position in top 20 percent from facial competence X ideology and facial dominance X ideology (Table 1: Model 2)
logit top20pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon i.conservative##c.Competence i.conservative##c.Dominance if local==1, cluster(Parti) 



****** FIGURES FROM ARTICLE
** FIGURE 1 - FACIAL COMPETENCE, ALL 257 CANDIDATES
logit top20pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon Competence i.conservative##c.Dominance if local==1, cluster(Parti)
summarize Competence if e(sample), detail
margins, at(Competence=(`r(p10)' `r(p90)'))

marginsplot, level(95) recast(dot) recastci(rcap) ylabel(0 (0.05) 0.4) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for position in Upper 20 percent of ballot") ///
title("") scheme(sol) name(Competence, replace)


** FIGURE 2 - FACIAL DOMINANCE, FOR LIBERAL AND CONSERVATIVE CANDIDATES, SEPARATELY
logit top20pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon Competence i.conservative##c.Dominance if local==1, cluster(Parti)
summarize Dominance if e(sample), detail

margins, at(Dominance=(`r(p10)' `r(p90)') conservative=(0))
marginsplot, level(95) recast(dot) recastci(rcap) ylabel(0 (0.05) 0.4) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for position in Upper 20 percent of ballot") ///
title("Liberal candidates") scheme(sol) name(Dominance_Liberal, replace)

logit top20pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon Competence i.conservative##c.Dominance if local==1, cluster(Parti)
summarize Dominance if e(sample), detail

margins, at(Dominance=(`r(p10)' `r(p90)') conservative=(1))
marginsplot, level(95) recast(dot) recastci(rcap) ylabel(0 (0.05) 0.4) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for position in Upper 20 percent of ballot") ///
title("Conservative candidates") scheme(sol) name(Dominance_Cons, replace)

graph combine Dominance_Liberal Dominance_Cons



**---------------------------------------------Supplementary analyses------------------------------------------------------------*
***** Analyses for models reported in footnotes in main text

** Supporting Information S.I.1 (Note 9 in main text)
* Candidate sex times facial competence interaction
logit top20pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon##c.Competence i.conservative##c.Dominance if local==1, cluster(Parti)


** Supporting Information S.I.2 (Note 10 in main text)
* Candidate sex times facial dominance interaction
logit top20pct i.Valgt_for i.Kommune ib(1).alder_ny i.conservative Competence i.Kon##c.Dominance if local==1, cluster(Parti)

* Candidate sex times facial dominance and ideology interaction
logit top20pct i.Valgt_for i.Kommune ib(1).alder_ny Competence i.Kon##i.conservative##c.Dominance if local==1, cluster(Parti)


***** Robustness analyses using alternative dependent measures (top25, top30, top40 and top50 percent), reported in Online Supporting Information 

*** Supporting Information S.I.3: Top 25 percent

** Main effect of facial competence + ideology X facial dominance
logit top25pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon c.Competence i.conservative##c.Dominance if local==1, cluster(Parti)

** Two interactions: ideology X facial competence + ideology X facial dominance
logit top25pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon i.conservative##c.Competence i.conservative##c.Dominance if local==1, cluster(Parti)



* Figure S.I.3a - Facial Competence
logit top25pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon Competence i.conservative##c.Dominance if local==1, cluster(Parti)
summarize Competence if e(sample), detail
margins, at(Competence=(`r(p10)' `r(p90)'))

marginsplot, level(95) recast(dot) recastci(rcap) ylabel(0 (0.1) 0.5) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for position in top 25 percent of ballot") ///
title("") scheme(sol) name(Competence25, replace)


* Figure S.I.3b - Facial Dominance
logit top25pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon Competence i.conservative##c.Dominance if local==1, cluster(Parti)
summarize Dominance if e(sample), detail

margins, at(Dominance=(`r(p10)' `r(p90)') conservative=(0))
marginsplot, level(95) recast(dot) recastci(rcap) ylabel(0 (0.1) 0.5) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for position in top 25 percent of ballot") ///
title("Liberal candidates") scheme(sol) name(Dominance_Liberal25, replace)

logit top25pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon Competence i.conservative##c.Dominance if local==1, cluster(Parti)
summarize Dominance if e(sample), detail

margins, at(Dominance=(`r(p10)' `r(p90)') conservative=(1))
marginsplot, level(95) recast(dot) recastci(rcap) ylabel(0 (0.1) 0.5) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for position in top 25 percent of ballot") ///
title("Conservative candidates") scheme(sol) name(Dominance_Cons25, replace)

graph combine Dominance_Liberal25 Dominance_Cons25



*** Supporting Information S.I.4: Top 30 percent
** Main effect facial competence + ideology X facial dominance
logit top30pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon Competence i.conservative##c.Dominance if local==1, cluster(Parti)

** Two interactions: ideology X facial competence + ideology X facial dominance
logit top30pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon i.conservative##c.Competence i.conservative##c.Dominance if local==1, cluster(Parti)


* Figure S.I.4a - Facial Competence
logit top30pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon Competence i.conservative##c.Dominance if local==1, cluster(Parti)
summarize Competence if e(sample), detail
margins, at(Competence=(`r(p10)' `r(p90)'))

marginsplot, level(95) recast(dot) recastci(rcap) ylabel(0 (0.05) 0.4) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for position in top 30 percent of ballot") ///
title("") scheme(sol) name(Competence30, replace)


* Figure S.I.4b - Facial Dominance
logit top30pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon Competence i.conservative##c.Dominance if local==1, cluster(Parti)
summarize Dominance if e(sample), detail

margins, at(Dominance=(`r(p10)' `r(p90)') conservative=(0))
marginsplot, level(95) recast(dot) recastci(rcap) ylabel(0 (0.05) 0.4) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for position in top 30 percent of ballot") ///
title("Liberal candidates") scheme(sol) name(Dominance_Liberal30, replace)

logit top30pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon Competence i.conservative##c.Dominance if local==1, cluster(Parti)
summarize Dominance if e(sample), detail

margins, at(Dominance=(`r(p10)' `r(p90)') conservative=(1))
marginsplot, level(95) recast(dot) recastci(rcap) ylabel(0 (0.05) 0.4) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for position in top 30 percent of ballot") ///
title("Conservative candidates") scheme(sol) name(Dominance_Cons30, replace)

graph combine Dominance_Liberal30 Dominance_Cons30



*** Supporting Information S.I.5: Top 40 percent
** Main effect facial competence + ideology X facial dominance
logit top40pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon Competence i.conservative##c.Dominance if local==1, cluster(Parti)

** Two interactions: ideology X facial competence + ideology X facial dominance
logit top40pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon i.conservative##c.Competence i.conservative##c.Dominance if local==1, cluster(Parti)


* Figure S.I.5a - Facial Competence
logit top40pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon Competence i.conservative##c.Dominance if local==1, cluster(Parti)
summarize Competence if e(sample), detail
margins, at(Competence=(`r(p10)' `r(p90)'))

marginsplot, level(95) recast(dot) recastci(rcap) ylabel(0 (0.1) 0.6) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for position in top 40 percent of ballot") ///
title("") scheme(sol) name(Competence40, replace)


* Figure S.I.5b - Facial Dominance
logit top40pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon Competence i.conservative##c.Dominance if local==1, cluster(Parti)
summarize Dominance if e(sample), detail

margins, at(Dominance=(`r(p10)' `r(p90)') conservative=(0))
marginsplot, level(95) recast(dot) recastci(rcap) ylabel(0 (0.1) 0.6) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for position in top 40 percent of ballot") ///
title("Liberal candidates") scheme(sol) name(Dominance_Liberal40, replace)

logit top40pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon Competence i.conservative##c.Dominance if local==1, cluster(Parti)
summarize Dominance if e(sample), detail

margins, at(Dominance=(`r(p10)' `r(p90)') conservative=(1))
marginsplot, level(95) recast(dot) recastci(rcap) ylabel(0 (0.1) 0.6) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for position in top 40 percent of ballot") ///
title("Conservative candidates") scheme(sol) name(Dominance_Cons40, replace)

graph combine Dominance_Liberal40 Dominance_Cons40



*** Supporting Information S.I.6: Top 50 percent
** Main effect facial competence + ideology X facial dominance
logit top50pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon Competence i.conservative##c.Dominance if local==1, cluster(Parti)

** Two interactions: ideology X facial competence + ideology X facial dominance
logit top50pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon i.conservative##c.Competence i.conservative##c.Dominance if local==1, cluster(Parti)


* Figure S.I.6a - Facial Competence
logit top50pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon Competence i.conservative##c.Dominance if local==1, cluster(Parti)
summarize Competence if e(sample), detail
margins, at(Competence=(`r(p10)' `r(p90)'))

marginsplot, level(95) recast(dot) recastci(rcap) ylabel(0 (0.1) 0.7) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for position in top 50 percent of ballot") ///
title("") scheme(sol) name(Competence50, replace)


* Figure S.I.6b - Facial Dominance
logit top50pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon Competence i.conservative##c.Dominance if local==1, cluster(Parti)
summarize Dominance if e(sample), detail

margins, at(Dominance=(`r(p10)' `r(p90)') conservative=(0))
marginsplot, level(95) recast(dot) recastci(rcap) ylabel(0 (0.1) 0.7) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for position in top 50 percent of ballot") ///
title("Liberal candidates") scheme(sol) name(Dominance_Liberal50, replace)

logit top50pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon Competence i.conservative##c.Dominance if local==1, cluster(Parti)
summarize Dominance if e(sample), detail

margins, at(Dominance=(`r(p10)' `r(p90)') conservative=(1))
marginsplot, level(95) recast(dot) recastci(rcap) ylabel(0 (0.1) 0.7) legend(off) ///
xlabel(#2) xtitle() ytitle("Predicted probability for position in top 50 percent of ballot") ///
title("Conservative candidates") scheme(sol) name(Dominance_Cons50, replace)

graph combine Dominance_Liberal50 Dominance_Cons50



*** Supporting Information S.I.7: Continuous nomination success measure: Ballot position relative to number of candidates within list
** Main effect facial competence + ideology X facial dominance
reg RelativListe i.Valgt_for i.Kommune ib(1).alder_ny i.Kon Competence i.conservative##c.Dominance if local==1, cluster(Parti)
margins, dydx(Dominance) at(conservative=(0 1))

** Two interactions: ideology X facial competence + ideology X facial dominance
reg RelativListe i.Valgt_for i.Kommune ib(1).alder_ny i.Kon i.conservative##c.Competence i.conservative##c.Dominance if local==1, cluster(Parti)


*** Supporting Information S.I.8: Effect of Facial Competence across all 268 candidates
logit top20pct i.Valgt_for i.Kommune ib(1).alder_ny i.Kon c.Competence c.Dominance, cluster(Parti)


